
<div class="wrap js-check-wrap">
    <!--平台选择-->
    <div class="well form-inline padding-top-10">
        <if condition="isset($platformArr)">
            <select class="chosen_select platform form-control" name="platform" onchange="changePlatform();">
                <foreach name="platformArr" item="v" key="k">
                    <option value="{$k}">{$v}</option>
                </foreach>
            </select>
        <else/>
            <input type="hidden" class="form-control platform" value="{$platform}"/>
        </if>
        <input class="form-control goServer" style="width: 100px;" placeholder="区服ID" type="text" onkeyup="value=value.replace(/[^\d\,]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d.]/g,''))"/>
        <button class="server_btn btn btn-primary">访问该服</button>
    </div>
    <!--平台选择end-->
    <!--区服选择-->
    <div class="server_info">
        <volist name="serverInfo" id="server">
            <a class="remoteLogin server color_{$server.status}_{$server.join_flag} go_{$server.platform}_{$server.plat_server} platform_{$server.platform}" data-plat_server="{$server.plat_server}" target="_blank" rel="{$server.domain}" href="javascript:void(0);" title="{$server.server_info}">s{$server.plat_server}</a>
        </volist>
    </div>
</div>

<!-- 实现rpc远程登录 -->
<script type="text/javascript">
    $(document).ready(function($){
        //带搜索的下拉框
        if($(".chosen_select").length){
            Wind.css("chosen");
            Wind.use("chosen",function(){
                $(".chosen_select").chosen();
            });
        }
        if($("select[name=platform]").length){
            var lastServerPlatform = getCookie("last_select_platform");
            $("select[name='platform']").find("option[value='" + lastServerPlatform + "']").attr("selected",true);
        }
        changePlatform();
        //跳转服
        $('button.server_btn').click(function(){
            var server_id = $('input.goServer').val();
            var platform = $(".platform").val();
            if(!isNum(server_id)) return false;
            var _url = "";
            $(".platform_" + platform).each(function(){
                var platServer = $(this).data("plat_server");
                if(platServer == server_id){
                    _url = $(this).attr("rel");
                    return false
                }else{
                    var servers = $(this).attr("title");
                    if(servers != "" && servers != "undefined"){
                        servers = servers.split(",");
                        if($.inArray(server_id,servers) != -1){
                            _url = $(this).attr("rel");
                            return false;
                        }
                    }
                }
            });
            if(_url){
                //检测区服是否存在
                _url = 'http://' + _url;
                var _serverUrl = '{:url("admin/Public/remoteLogin", "", false, true)}';
                remoteLogin(_serverUrl, _url);
            }else{
                dialogAlert("",'访问的区服('+ server_id +')不存在');
            }
            return false;
        });
        //远程登录
        $('a.remoteLogin').click(function(e){
            e.preventDefault();
            var _url = 'http://' + $(this).attr('rel');
            var _serverUrl = '{:url("admin/Public/remoteLogin", "", false, true)}';
            remoteLogin(_serverUrl, _url);
            return false;
        })
    });
    //平台选择
    function changePlatform()
    {
        var platform = $(".platform").val();
        $('.server_info i.tipInfo').remove();
        if(platform == ""){
            $('.server_info a.server').hide();
            $('.server_info').append('<i class="tipInfo">请选择一个平台...</i>');
        }else{
            $('.server_info a.server').hide();
            $('.server_info a.platform_' + platform).show();
            if($('.server_info a.server:visible').length == 0){
                $('.server_info').append('<i class="tipInfo">该平台还未配置服务器...</i>');
            }
            setCookie("last_select_platform",platform);
        }
    }
</script>